package com.hjn.springboot.springbootinterceptor.config;

import com.hjn.springboot.springbootinterceptor.interceptor.MyInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author huaijn
 * @date 2022/4/25 /0025-13:41
 * @description todo
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    //定义要拦截的路径
    String[] addPathPatterns = {
            "/user/**"
    };

    //排除不需要拦截的路径
    String[] excludePathPatterns = {
            "/user/page/login",
            "/user/login"  ,
            "/user/nologin"
    };

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(new UserInteceptor())
                .addPathPatterns(addPathPatterns)
                .excludePathPatterns(excludePathPatterns);
    }
}
